home *** CD-ROM | disk | FTP | other *** search
/ SunSoft Catalyst CDWARE 1996 May to August / Catalyst CDWARE 1996 May to August.iso / .products / .bin / httpd / Solaris_2 / edit_info.pl < prev    next >
Perl Script  |  1996-02-26  |  12KB  |  375 lines

  1. #!./perl
  2.  
  3. # ------------------------------------------------------------
  4.  
  5. # edit_info.pl, by Jean-Pierre Girard (jpg@corrado.sun.com)
  6. # This allows the user to edit or create the _info file
  7. # necessary for the CDware.
  8.  
  9. # ------------------------------------------------------------
  10.  
  11. # Bugs and other fixes
  12.  
  13. # ------------------------------------------------------------
  14. %Categories = (
  15. "archive", "Archiving, Storage Management & Backup Solutions"
  16. ,"business", "Business Solutions"
  17. , "cad_cae", "CAD/CAE"
  18. , "catalogs", "Catalogs"
  19. , "client_server", "Client/Server Solutions"
  20. , "desktop_apps", "Desktop Applications"
  21. , "doc_mgt", "Document Management"
  22. , "epubs", "Electronic Publishing"
  23. , "graphics_imaging", "Graphics and Imaging"
  24. , "info_mgt", "Information Management"
  25. , "multimedia", "Multimedia"
  26. , "networking", "Networking"
  27. , "security", "Security"
  28. , "sw_eng", "Software Engineering"
  29. , "sys_admin", "System Administration"
  30. , "telco", "Telecommunications"
  31. , "training", "Training"
  32. , "Hardware", "Hardware"
  33. , "Services", "Services"
  34. , "internet", "Internet"
  35. , "Info", "Info"
  36. );
  37.  
  38. @PlatOrder = ("S2", "S1", "S2x86", "S2PPC");
  39.  
  40. %Platforms = (
  41. "S1", "Solaris 1 (SunOS 4)"
  42. , "S2", "Solaris 2 SPARC"
  43. , "S2x86", "Solaris 2 Intel"
  44. , "S2PPC", "Solaris 2 PowerPC"
  45. );
  46.  
  47. sub IsSelected
  48. {
  49.     local($KeyCat) = @_;
  50.     @fields = split(/\s+/, $ChosenCat);
  51.     foreach $idem (@fields) {
  52.         if ($idem eq $KeyCat) {
  53.             "SELECTED";
  54.             last;
  55.         }
  56.     }
  57. }
  58.  
  59. sub UnCapitalizedSort
  60. {
  61.     ($al = $a) =~ tr/A-Z/a-z/;
  62.     ($bl = $b) =~ tr/A-Z/a-z/;
  63.     $al cmp $bl;
  64. }
  65.  
  66. ##############################################################################
  67. # WriteForm: Write the form to be filled by the user
  68. ##############################################################################
  69. sub WriteForm
  70. {
  71.     $~ = "MAININFO";
  72.     write STDOUT;
  73.  
  74.     $~ = "PLATINFO";
  75.     #foreach $NickPlat (sort UnCapitalizedSort keys(%Platforms)) {
  76.     foreach $NickPlat (@PlatOrder) {
  77.         write STDOUT;
  78.     }
  79.  
  80.     $~ = "MIDINFO";
  81.     write STDOUT;
  82.  
  83.     $~ = "CATINFO";
  84.     foreach $NickCat (sort UnCapitalizedSort keys(%Categories)) {
  85.         $CatName = $Categories{$NickCat};
  86.         unless ($CatName =~ /^!.*/) {
  87.             write STDOUT;
  88.         }
  89.     }
  90.  
  91.     $~ = "ENDINFO";
  92.     write STDOUT;
  93. }
  94. ##############################################################################
  95. # CreateHTML: Create an HTML page initialized with the _info file content
  96. ##############################################################################
  97. sub CreateHTML
  98. {
  99.     if (-s $INFOFILENAME && open (INFOFILE, $INFOFILENAME)) {
  100.         $LINE=<INFOFILE>;
  101.         ($Company, $Description, $Platform, $ChosenCat, $WebSite, $Email, $HomePageName) = split(/\^/, $LINE);
  102.         $Company="value=\"" . $Company . "\"";
  103.         $Description="value=\"" . $Description . "\"";
  104.         $WebSite="value=\"" . $WebSite . "\"";
  105.         $Email="value=\"" . $Email . "\"";
  106.     
  107.         @fields = split(/\s+/, $Platform . " " . $ChosenCat);
  108.         foreach $idem (@fields) {
  109.             $Checked{$idem} = "CHECKED"
  110.         }
  111.         while (<INFOFILE>) {
  112.             $Product=$_;
  113.             chop($Product);
  114.             chop($Product);
  115.             push(@Products, "value=\"" . $Product . "\"");
  116.         }
  117.     } else {
  118.     }
  119.  
  120.     $HomePageName="value=\"" . ($HomePageName =~ /^ *$/?"index.html":$HomePageName) . "\"";
  121.  
  122.     $~ = "HTMLHEADER";
  123.     write STDOUT;
  124.  
  125.     &WriteForm();
  126. }
  127.  
  128. sub url_decode
  129. {
  130.  
  131. #       Decode a URL encoded string or array of strings
  132. #               + -> space
  133. #               %xx -> character xx
  134.  
  135.  
  136.     foreach (@_) {
  137.         tr/+/ /;
  138.         s/%0a //g;
  139.         s/\^//g;
  140.         s/%(..)/pack("c",hex($1))/ge;
  141.     }
  142.     @_;
  143. }
  144.  
  145. sub Init
  146. {
  147.     local($comp, $errMes) = @_;
  148.     $comp=$rqpairs{$comp};
  149.     if ($comp eq "") {
  150.         $Status = &PrintErr($errMes);
  151.     }
  152.     $comp;
  153. }
  154.  
  155. sub WriteInfo
  156. {
  157.     local($old);
  158.     $~ = "HTMLHEADER";
  159.     write STDOUT;
  160.  
  161.     @names = &url_decode(split(/[&=]/, $request));
  162.     %rqpairs = @names;
  163.     open (INFOFILE, "> $INFOFILENAME");
  164.     $old = select(INFOFILE);
  165.  
  166.     $Company = &Init("CompanyName", "MisCompany");
  167.     $Description = &Init("Description", "MisDescription");
  168.     $Description =~ s/^[-     ]*/- /;
  169.     $WebSite = $rqpairs{"WebSite"};
  170.     $WebSite =~ s/^\///;
  171.     $WebSite =~ s/^http:\/\///;
  172.     #$WebSite =~ s/\/$//;
  173.     $Email = $rqpairs{"Email"};
  174.     $HomePageName = &Init("Home", "MisHome");;
  175.     $Products[0] = &Init("Product1", "MisProduct1");
  176.     $Products[1] = $rqpairs{"Product2"};
  177.     $Products[2] = $rqpairs{"Product3"};
  178.  
  179.     substr($Company, 0, 1) =~ tr/a-z/A-Z/;
  180.     print $Company . "^" . $Description . "^";
  181.     print ($rqpairs{"hasSlide"} eq "yes" ? "demo ":"");
  182.     print ($rqpairs{"hasTryIt"} eq "yes" ? "testdrive ":"");
  183.     print ($rqpairs{"hasInstall"} eq "yes" ? "install":"");
  184.     print "^";
  185.     %RevCat = reverse %Categories;
  186.     %RevPlat = reverse %Platforms;
  187.     $foundCat = $foundPlat = 0;
  188.     $ChosenCat = "";
  189.     for ($iname = 0; $iname < @names; $iname+=2) {
  190.         if ($names[$iname] eq "Menu_Cat") {
  191.             $ChosenCat = $ChosenCat . $RevCat{$names[$iname + 1]} . " ";
  192.             print $RevCat{$names[$iname + 1]} . " ";
  193.             $foundCat++;
  194.         } elsif ($names[$iname] eq "Menu_Plat") {
  195.             $buf = $names[$iname + 1];
  196.             $buf =~ s/ *$//;
  197.             $Checked{$RevPlat{$buf}} = "CHECKED";
  198.             print $RevPlat{$buf} . " ";
  199.             $foundPlat++;
  200.         }
  201.     }
  202.     if ($foundPlat == 0) {
  203.         $Status = &PrintErr("MisPlat");
  204.     }
  205.     if ($foundCat == 0) {
  206.         $Status = &PrintErr("MisCat");
  207.     } elsif ($foundCat > 3) {
  208.         $Status = &PrintErr("TooManyCat");
  209.     }
  210.     $WebSite =~ s/[     ]//g;
  211.     $Email =~ s/[     ]//g;
  212.     $HomePageName =~ s/[     ]//g;
  213.     print "^$WebSite^$Email^$HomePageName^\n";
  214.     print "$Products[0]^\n";
  215.     if ($Products[1] ne "") {
  216.         print "$Products[1]^\n";
  217.     }
  218.     if ($Products[2] ne "") {
  219.         print "$Products[2]^\n";
  220.     }
  221.     close(INFOFILE);
  222.     select($old);
  223.     if ($Status == 1) {
  224.         $Company="value=\"" . $Company . "\"";
  225.         $Description="value=\"" . $Description . "\"";
  226.         $WebSite="value=\"" . $WebSite . "\"";
  227.         $Email="value=\"" . $Email . "\"";
  228.         $HomePageName="value=\"" . $HomePageName . "\"";
  229.         ($rqpairs{"hasSlide"} eq "yes" ? $Checked{"demo"} = "CHECKED":null);
  230.         ($rqpairs{"hasTryIt"} eq "yes" ? $Checked{"testdrive"} = "CHECKED":null);
  231.         ($rqpairs{"hasInstall"} eq "yes" ? $Checked{"install"} = "CHECKED":null);
  232.         for ($iprod = 0; $iprod < 3; $iprod++) {
  233.             $Products[$iprod]= "value=\"" . $Products[$iprod] . "\"";
  234.         }
  235.         &WriteForm();
  236.     } else {
  237.         $~ = "GOODRESULT";
  238.         write STDOUT;
  239.     }
  240. }
  241.  
  242. ##############################################################################
  243. # Main block
  244. ##############################################################################
  245. require 'devinfo.pl';
  246. require 'tools.pl';
  247. $HomeDir = &GetDevinfo("dir");
  248. $INFOFILENAME = "$HomeDir/_info";
  249.  
  250. if ($ENV{'REQUEST_METHOD'} eq "POST") {
  251.     read(STDIN, $request, $ENV{'CONTENT_LENGTH'});
  252. } elsif ($ENV{'REQUEST_METHOD'} eq "GET" ) {
  253.     $request = $ENV{'QUERY_STRING'};
  254. }
  255. $Checked{"S2"} = "CHECKED";
  256. if ($ARGV[0] eq "HTML") {
  257.     &CreateHTML;
  258. } elsif ($request eq "") {
  259.     print "no request";
  260. } else {
  261.     &WriteInfo;
  262. }
  263.  
  264. ################################################################################
  265. # Define FORMATS (no more code)
  266. ################################################################################
  267. format HTMLHEADER =
  268. Content-type: text/html
  269.  
  270.  
  271. <html>
  272. <title>Developer's Kit: edit information</title>
  273. <body>
  274. .
  275.  
  276. format MAININFO =
  277. <h1>Please enter this information and click on "Ok":</h1>
  278. <h4>Currently working with <b>"@*
  279. $HomeDir
  280. " directory</h4>
  281. #<p>You 're currently editing <b>@* 
  282. #$INFOFILENAME
  283. </b><form method="post"  ACTION="http://localhost:7999/cgi-bin/edit_info.pl">
  284. #<h4>CDware _info file: </h4>
  285. <ul><IMG src="file:///tmp/httpd/.products/DEV/images/bullet_ball_red.gif">: necessary
  286. <IMG src="file:///tmp/httpd/.products/DEV/images/bullet_ball_green.gif">: Optional.</ul>
  287. <pre><IMG src="file:///tmp/httpd/.products/DEV/images/bullet_ball_red.gif">Company name:       <input type="text" 
  288. ~@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  289. $Company
  290.  name="CompanyName" size="25" maxlength=50>
  291. <IMG src="file:///tmp/httpd/.products/DEV/images/bullet_ball_red.gif">Brief description:  <input type="text"
  292. ~~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  293. $Description
  294.  name="Description" size=62 MAXLENGTH=160>
  295. <IMG src="file:///tmp/httpd/.products/DEV/images/bullet_ball_red.gif">First Product Name: <input type="text"
  296. ~@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  297. $Products[0]
  298.  name="Product1" size="35" maxlength=50>
  299. <IMG src="file:///tmp/httpd/.products/DEV/images/bullet_ball_green.gif">Second Product Name:<input type="text"
  300. ~@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  301. $Products[1]
  302.  name="Product2" size="35" maxlength=50>
  303. <IMG src="file:///tmp/httpd/.products/DEV/images/bullet_ball_green.gif">Third Product Name: <input type="text"
  304. ~@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  305. $Products[2]
  306.  name="Product3" size="35" maxlength=50><br>
  307. <IMG src="file:///tmp/httpd/.products/DEV/images/bullet_ball_green.gif">Address of your web site: http://<input type="text"
  308. ~~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  309. $WebSite
  310.  name="WebSite" size=28 MAXLENGTH=160>/
  311. <IMG src="file:///tmp/httpd/.products/DEV/images/bullet_ball_green.gif">Email for information request:   <input type="text"
  312. ~~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  313. $Email
  314.  name="Email" size=28 MAXLENGTH=160>
  315. <IMG src="file:///tmp/httpd/.products/DEV/images/bullet_ball_red.gif">Filename of your home page:      <input type="text"
  316. ~~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  317. $HomePageName
  318.  name="Home" size=28 MAXLENGTH=160>
  319. </pre>
  320. <IMG src="file:///tmp/httpd/.products/DEV/images/bullet_ball_red.gif">Specify if there will be a Slide-show or a version of your product available for evaluation in your submission:
  321. <ul><ul>
  322. <input type="checkbox" NAME="hasSlide" VALUE="yes" @<<<<<<<<< size="8" >Slide-show available<br>
  323. $Checked{"demo"}
  324. <input type="checkbox" NAME="hasTryIt" VALUE="yes" @<<<<<<<<< size="8" >Trial software available<br>
  325. $Checked{"testdrive"}
  326. <input type="checkbox" NAME="hasInstall" VALUE="yes" @<<<<<<<<<< size="8" >Unlockable available<br>
  327. $Checked{"install"}
  328. <IMG ALIGN=middle src="file:///tmp/httpd/.products/DEV/images/finger.gif"><b>Note:</b> If you do NOT have any of the above, please continue.<br>
  329. </ul></ul>
  330. <p><IMG src="file:///tmp/httpd/.products/DEV/images/bullet_ball_red.gif">Specify which platforms you're supporting (at least one):
  331. <ul><ul>
  332. .
  333.  
  334. format PLATINFO =
  335. <input type="checkbox" NAME="Menu_Plat" VALUE="@<<<<<<<<<<<<<<<<<<" @<<<<<<<<<< size="8" >@<<<<<<<<<<<<<<<<<<< <br>
  336. $Platforms{$NickPlat}, $Checked{$NickPlat}, $Platforms{$NickPlat}
  337. .
  338.  
  339. format MIDINFO =
  340. </ul></ul>
  341. <IMG src="file:///tmp/httpd/.products/DEV/images/bullet_ball_red.gif">Choose one to three categories:<br>
  342. <p><center><SELECT NAME="Menu_Cat" size="10" MULTIPLE>
  343. .
  344.  
  345. format CATINFO =
  346. <OPTION @<<<<<<<<> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
  347. &IsSelected($NickCat), $CatName
  348. .
  349.  
  350. format ENDINFO =
  351. </SELECT></center><br>
  352. <P><center>
  353. <input type="submit" VALUE="Ok" >
  354. <input type="Reset" VALUE="Cancel" >
  355. </center>
  356. </FORM>
  357. <hr><h5><p><A HREF=file:///tmp/httpd/.products/CDware/Help/SMICopyright.html>Copyright</A> 1995 Sun Microsystems, Inc., 2550 Garcia Ave., Mtn. View, CA 94043 USA.  All rights reserved.</h5><br></pre>
  358. <a href=file:///tmp/httpd/.products/DEV/credits.html>Credits</a>
  359. </b>
  360. </body>
  361. </html>
  362. .
  363.  
  364.  
  365. format GOODRESULT =
  366. <h1><app class="ImageLoopItem" img="file:///tmp/httpd/.products/DEV/images/duke" width=55 height=68>Congratulations! </h1>
  367. <p>You completed the first step of the creation of your submssion to the CDware.
  368. <p>You can edit this information again at any time from the main menu !
  369. <h4><p><A HREF="http://localhost:7999/cgi-bin/mainmenu.pl? ">Go to main menu</A> </h4><br>
  370. #<hr><h5><p><A HREF=file:///tmp/httpd/.products/CDware/Help/SMICopyright.html>Copyright</A> 1995 Sun Microsystems, Inc., 2550 Garcia Ave., Mtn. View, CA 94043 USA.  All rights reserved.</h5><br></pre>
  371. #<a href=file:///tmp/httpd/.products/DEV/credits.html>Credits</a>
  372. </body>
  373. </html>
  374. .
  375.